package com.ruoyi.web.controller.mxerp;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.MxWare;
import com.ruoyi.system.domain.MxWareIn;
import com.ruoyi.system.domain.MxWareOut;
import com.ruoyi.system.domain.VMxProductWare;
import com.ruoyi.system.service.IMxWareService;
import com.ruoyi.system.service.MxInOutService;
import com.ruoyi.system.service.VMxProductWareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品出入库管理
 */
@RestController
@RequestMapping("/mxerp/inout")
public class MxInOutController extends BaseController {
    @Autowired
    private IMxWareService mxWareService;

    @Autowired
    private MxInOutService mxInOutService;

    @Autowired
    private VMxProductWareService vMxProductWareService;



    @PreAuthorize("@ss.hasPermi('mxerp:inout:list')")
    @GetMapping("/list")
    public TableDataInfo list(VMxProductWare vMxProductWare) {
        startPage();
        List<VMxProductWare> list = vMxProductWareService.selectVMxProductWareList(vMxProductWare);//.selectMxWareList(mxWare);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('mxerp:inout:add')")
    @PostMapping("insave")
    public AjaxResult add(@RequestBody MxWareIn mxWareIn) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        mxWareIn.setUserId(user.getUserId()+"");
        mxInOutService.insaveWare(mxWareIn);
        return success();
    }


    @PreAuthorize("@ss.hasPermi('mxerp:inout:out')")
    @PostMapping("outSave")
    public AjaxResult out(@RequestBody MxWareOut mxWareOut) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        mxWareOut.setUserId(user.getUserId()+"");
         mxInOutService.outSaveWare(mxWareOut);
        return success();
    }
}
